Ext.require([
    'Ext.form.*',
    'Ext.data.*',
    'Ext.layout.container.Column',
    'Ext.tab.TabPanel'
]);


/*!
 * Ext JS Library 3.3.1
 * Copyright(c) 2006-2010 Sencha Inc.
 * licensing@sencha.com
 * http://www.sencha.com/license
 */
Ext.onReady(function(){

    Ext.QuickTips.init();

    var bd = Ext.getBody();
    
    var fp = Ext.create('Ext.form.FormPanel', {
		id: 'fp',
        border:false,
        width: 350,
        fieldDefaults: {
            labelWidth: 75,
            msgTarget: 'side'
        },
        defaults: {
            anchor: '100%'
        },

        items: [
				{
					xtype: 'textfield',
					fieldLabel: 'Email',
					anchor: '100%',
					name: 'memberEmail',
					id: 'memberEmail',
					vtype:'email',
					value: 'admin@cattolica-places.com'
				},
				{
					xtype: 'textfield',
					fieldLabel: 'Password',
					inputType: 'password',
					anchor: '100%',
					name: 'memberPassword',
					id: 'memberPassword',
                    value: 'super4'
				}
            ],
                   
        buttons: [{
            text: 'Entra',
            disabled: true,
            formBind: true,
			handler: function() {
				var form = this.up('form').getForm();
				if (form.isValid()) {
					form.submit({
						url: '../../cattolica-web/login',
	                    submitEmptyText: false,
						success: function(form, action) {
						   Ext.util.Cookies.set('memberEmail', form.getValues().memberEmail);
						   Ext.util.Cookies.set('memberPassword', form.getValues().memberPassword);
						   document.location = 'item/list.html';
						},
						failure: function(form, action) {
							Ext.Msg.alert('Failed', action.response.statusText);
						}
					});
				}
			}
        },
		{
            text: 'Sono Nuovo!',
			handler: function() {
				document.location = 'item/add.html';
			}
        }			
		
		]
    });

	Ext.util.Cookies.clear('memberEmail');
	Ext.util.Cookies.clear('memberPassword');

    fp.render(document.body);

});

